// home.js
const F = require('../../utils/util');
const app = getApp()
Page({
  data: {
    current: 0,
    time:{},
    dates: {},
    hour: 0,
    minute: 0,
    secnd: 0,
    bgImg: '../images/huangchao.png',
    name: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
 
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    let age = wx.getStorageSync('user_info'),_that = this;
    let time = F.formatTime(new Date());
    let dates = F.getDatas(age.age, 1);
    this.setData({
      time: time,
      dates: dates,
    })
    app.getUserInfo(function(userinfo) {
      let dates = F.getDatas(age.age, userinfo.gender);
      // console.log(userinfo)
      _that.setData({
        dates: dates,
        bgImg: userinfo.avatarUrl,
        name: userinfo.nickName,
      })
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let _that = this;
    setInterval(function() {
      let time = new Date();
      let hour = time.getHours();
      let minute = time.getMinutes();
      let secnd = time.getSeconds();
      let hR = (hour + (minute/60) + (secnd/3600))*30;
      let mR = (minute + (secnd/60)) * 6;
      let sR = secnd * 6;
      _that.setData({
        hour: hR,
        minute: mR,
        secnd: sR,
      })
    },1000)
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '我们还剩下多少时间',
      path: 'pages/index/index'
    }
  },
  chage_item: function(e) {
    let index = e.target.dataset.index;
    this.setData({
      current: index 
    })
  },
  change_swiper: function(e) {
    let index = e.detail.current;
    this.setData({
      current: index
    })
  },
  callHc: function() {
    console.log('ds')
    wx.makePhoneCall({
      phoneNumber: '18012806480'
    })
  }
})